#!/bin/bash

# 设置UTF-8编码环境变量
export LANG=zh_CN.UTF-8
export LC_ALL=zh_CN.UTF-8
export PYTHONIOENCODING=utf-8

echo "==================================================="
echo "====        EEG信号处理应用打包工具           ===="
echo "==================================================="
echo ""

# 打印系统编码信息，帮助诊断
echo "系统语言环境: $LANG"
echo "Python IO编码: $PYTHONIOENCODING"

# 使脚本可执行
chmod +x build_app.py

# 检查Python环境
if ! command -v python3 &> /dev/null; then
    echo "错误: 未找到Python，请确保Python已安装"
    exit 1
fi

# 检查PyInstaller
if ! python3 -c "import PyInstaller" &> /dev/null; then
    echo "警告: 未找到PyInstaller，正在安装..."
    pip3 install pyinstaller
    if [ $? -ne 0 ]; then
        echo "错误: 安装PyInstaller失败，请手动安装"
        exit 1
    fi
fi

# 运行打包脚本
echo "正在启动打包过程..."
python3 build_app.py

if [ $? -ne 0 ]; then
    echo "打包过程失败，请检查错误信息"
    exit 1
else
    echo "打包过程完成"
fi

echo ""
echo "按Enter键退出..."
read 